function actionGetResolution() {
    var conf = ['1080p', '720p', '480p'];
    var res = '';
    if(Lib.inArray(window.location.hash.substring(1), conf)) {
        res = window.location.hash.substring(1);
    } else {
        res = Lib.getCookie('resolution');
    }
    if(res == '') {
        res = '720p';
    }
    return 'resolution_' + res;
}
function attachEventChooseResolution() {
    var els = document.getElementById('resolution').getElementsByTagName('a');
    for(var i=0, l=els.length; i<l; i++) {
        els[i].onclick = function() {
            actionChooseResolution(this.id);
            return false;
        }
    }
}
function actionChooseResolution(id) {
    var els = document.getElementById('resolution').getElementsByTagName('a');
    for(var i=0, l=els.length; i<l; i++) {
        els[i].className = '';
    }
    var el = document.getElementById(id);
    el.className = 'visiting';
    //链接变来变去没用，因为用户不需要后退也不需要看见变化。
    //当一个电影只有480p时，需要复制分享给别人，所以开启#
    window.location.replace(el.href); //使用这个不会留下history，因为切换分辨率时不留history的体验好。参考http://www.w3cmm.com/javascript/location.html
    var res = el.getAttribute('data-resolution');
    var els = document.getElementsByClassName('uri_at_one_resolution');
    for(var i=0, l=els.length; i<l; i++) {
        els[i].style.display = 'none';
    }
    if(document.getElementById('uri_' + res) != null) {
        document.getElementById('uri_' + res).style.display = 'block';
    }
    Lib.setCookie('resolution', res, 29, '/subject');
    return true;
}
function attachEventDisablePtUri()
{
        var els = document.getElementsByClassName('uri_pt_disable');
        for(var i=0, l=els.length; i<l; i++) {
            els[i].onclick = function()
            {
                return false;
            }
        }
}
function actionShowPtUri()
{
    var callback = function(xmlhttp) {
        console.log(xmlhttp.responseText);
        var user = JSON.parse(xmlhttp.responseText);
        var els = document.getElementsByClassName('uri_pt_disable');
        for(var i=0, l=els.length; i<l; i++) {
            els[i].href = els[i].getAttribute('data-href') + '?passkey=' + user.passkey;
            els[i].title = '';
            els[i].onclick = function()
            {
            }
            els[i].className = '';
        }
    }
    Lib.http('get', '/api/me', '', callback, false);
}
function actionShowFreeDirectDownload()
{
    var callback = function(xmlhttp) {
        console.log(xmlhttp.responseText);
        var user = JSON.parse(xmlhttp.responseText);
        if(document.getElementById('free_direct_download') != null) {
            document.getElementById('free_direct_download').style.display = 'block';
        }
    }
    Lib.http('get', '/api/me', '', callback, false);
}
